﻿Imports System
Imports System.Threading
Imports System.Drawing
Imports System.Windows.Forms

Public Class Loading

    Implements IDisposable
    Private Lform As New frmWait
    Private LLocation As Point

    Public Sub Dispose() Implements System.IDisposable.Dispose
        Try
            Lform.Invoke(New MethodInvoker(AddressOf stopThread))
        Catch ex As Exception
            Lform.Close()
        End Try
    End Sub

    Public Sub New(ByVal location As Point)
        MyBase.New()
        Try
            LLocation = location
            Dim t As Thread = New Thread(New ThreadStart(AddressOf workerThread))
            t.IsBackground = True
            t.SetApartmentState(ApartmentState.STA)
            t.Start()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub stopThread()
        Lform.Close()
    End Sub

    Private Sub workerThread()
        Lform = New frmWait
        Lform.Location = LLocation
        Lform.TopMost = True
        Application.Run(Lform)
    End Sub

End Class